package cn.lj.payment.config;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayConstants;
import com.ijpay.alipay.AliPayApiConfig;
import com.ijpay.alipay.AliPayApiConfigKit;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AliPayConfig {


    @Bean
    public AliPayApiConfig aliPayApiConfig(
            @Value("${alipay.appid}")String appid,
            @Value("${alipay.merchantPrivateKey}")String PrivateKey,
            @Value("${alipay.rootCertPath}")String rootCertPath,
            @Value("${alipay.appCertPath}")String appCertPath,
            @Value("${alipay.certPath}")String certPath,
            @Value("${alipay.gatewayUrl}")String gatewayUrl
    ) throws AlipayApiException {
        AliPayApiConfig aliPayApiConfig = AliPayApiConfig.builder()
                .setAppId(appid)//appid
                .setPrivateKey(PrivateKey)//应用私钥
                .setAliPayCertPath(certPath)//支付宝公钥证书
                .setAppCertPath(appCertPath)//应用证书目录
                .setAliPayRootCertPath(rootCertPath)//支付宝根证书
                .setServiceUrl(gatewayUrl)//网关
                .setSignType(AlipayConstants.SIGN_TYPE_RSA2).buildByCert();//签名算法
        return AliPayApiConfigKit.putApiConfig(aliPayApiConfig);
    }
}
